<?php
/**
 * 优惠券内容表
 *
 * @author Zeon <scplay@gmail.com>
 * @date 2019/5/7
 * @copyright PanxSoft Inc.
 */
namespace App\Models\Coupon;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;

/**
 * Class CouponCard
 *
 * @property float probability
 * @property int expired_in
 * @property int is_available
 * @property int type
 * @property int score
 * @property string title
 * @property string description
 * @property Carbon started_at
 * @property Carbon ended_at
 *
 * @package App\Models\Coupon
 *
 * @mixin Builder
 * @mixin \Illuminate\Database\Query\Builder
 */
class CouponTicket extends Model
{
    protected $table = 'coupon_tickets';
    protected static $unguarded = true;

    const MAX_COUNT = 8;
    const IS_AVAILABLE = 1;

    protected $casts = [
        'is_available' => 'int',
        'sort_order'   => 'int',
        'expired_in'   => 'int',
        'probability'  => 'float',
        'score'        => 'int',
        'type'         => 'int',
    ];

    protected $dates = ['started_at', 'ended_at'];

    const TYPE_NONE = 0;
    const TYPE_AWARD = 1;
    const TYPE_SCORE = 2;

    const VALIDATE_TYPES = [
        self::TYPE_NONE,
        self::TYPE_AWARD,
        self::TYPE_SCORE,
    ];

    public function isTypeScore()
    {
        return $this->type === self::TYPE_SCORE;
    }
}